package com.jkhan.springframework.beans.facroty.support;

import com.jkhan.springframework.beans.BeansException;
import com.jkhan.springframework.beans.facroty.BeanFactory;
import com.jkhan.springframework.beans.facroty.config.BeanDefinition;

/**
 * @ClassName AbstractBeanFactory
 * @Description AbstractBeanFactory
 * @Author hjk
 * @Date 2022/11/27 16:51
 **/
public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {

    public Object getBean(String name) throws BeansException {
        Object bean = getSingleton(name);
        if (bean != null) {
            return bean;
        }

        BeanDefinition beanDefinition = getBeanDefinition(name);
        return creatBean(name, beanDefinition);
    }

    protected abstract Object creatBean(String beanName, BeanDefinition beanDefinition) throws BeansException;

    protected abstract BeanDefinition getBeanDefinition(String beanName) throws BeansException;

}
